<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>06_事件操作-阻止事件行为</title>
  <style>
    .box{
      width: 200px;
      height: 200px;
      background-color: pink;
    }
    .content{
      display: inline-block;
      width: 50px;
      height: 50px;
      background-color: green;
    }
  </style>
</head>
<body>

  <div class="box">
    div
    <span class="content">span</span>
  </div>

  <a href="https://www.jd.com">京东商城</a>

  <script src="../libs/jquery-3.6.0.js"></script>
  <script>

    $(function () {
      $('a').click(function (e) {
        e.preventDefault() // 阻止默认行为
        console.log('阻止默认行为 a 元素');
      })

      $('.content').click(function (e) {
        e.stopPropagation() // 阻止事件冒泡
        console.log('阻止事件冒泡 box 元素');
      })
      $('.box').click(function () {
        console.log('box 元素')
      })
    })

   

  </script>
  
</body>
</html>